package net.loyin.app.ctrl.front;

import net.loyin.annotation.ControllerBind;
import net.loyin.app.model.Article;
import net.loyin.app.model.ArticleCate;
import net.loyin.app.model.NavMenu;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * 前端首页
 * Created by loyin on 16/1/12.
 */
@ControllerBind(route = SchoolCtrl.base)
public class SchoolCtrl extends FrontBaseCtrl{
    public static final String base="/school";

    public void index() {
        String para=this.getPara(0);
        if(StringUtils.isNotBlank(para)) {
            String jumpUrl = NavMenu.dao.hasJumpUrl(base+"/"+ para, 1);
            if (StringUtils.isNotBlank(jumpUrl)) {
                this.forwardAction(jumpUrl);
            }
        }
    }
    public void view(){
        this.setNavInfo();
        String id = this.getPara(0);
        if (StringUtils.isNotBlank(id)) {
            this.setAttr("po", Article.dao.findById(id));
        }
    }
    /**
     * /school/news/{pageNumber}-{pageSize}
     */
    public void news(){
        String articleCateCode="news";
        this.setNavInfo(base+"/"+articleCateCode);
        StringBuffer sql=new StringBuffer();
        sql.append(" from ");
        sql.append(Article.tableName);
        sql.append(" as a ,");
        sql.append(ArticleCate.tableName);
        sql.append(" as ac where a.cate_id=ac.id and ac.code like ? and ac.status=1 and a.status=1 order by a.create_datetime desc");
        this.setAttr("page", Article.dao.paginate(this.getParaToInt(0,1),this.getParaToInt(1,8),"select a.id,a.title,a.summary,a.create_datetime,ac.name cate_name ",sql.toString(),articleCateCode));
    }
}
